<template>
  <el-dialog :title="title" :visible="visiable" append-to-body @close="close">
    <div>
      <el-form ref="formChangePayment" :model="form" label-width="100px">
        <el-form-item label="提现金额">
          <el-input v-model="form[disableColumn]" disabled></el-input>
        </el-form-item>
        <el-form-item label="提现状态" required>
          <el-radio-group v-model="form[column]" @change="change">
            <el-radio :label="0" :value="0">未打款</el-radio>
            <el-radio :label="1" :value="1">已打款</el-radio>
          </el-radio-group>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer algin">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </div>
  </el-dialog>
</template>

<script>
import RequestRemote from "../../../../utils/request";
export default {
  name: "duplicateCheckCoupon",
  props: {
    visiable: {
      type: Boolean,
      default: false,
    },
    Obj: {
      type: Object,
      default: {},
    },
    // 第二个字段 要更新的
    column: {
      type: String,
      default: "",
    },
    disableColumn: {
      type: String,
      default: "account",
    },
    requestURL: {
      type: String,
      default: "",
    },
    title: {
      type: String,
      default: "",
    }
  },
  computed: {
    dialogVisible: {
      get() {
        return this.visiable;
      },
      set() {
        this.close();
        this.reset();
      },
    },
  },
  data() {
    return {
      form: {
        id: 0,
      },
    };
  },
  mounted() { },

  watch: {
    visiable: {
      handler(value) {
        if (value) {
          this.form.id = this.Obj.id;
          this.form[this.disableColumn] = this.Obj[this.disableColumn];
          this.form[this.column] = this.Obj[this.column];
        }
      },
      deep: true
    }
  },

  methods: {
    change(e) {

      this.$forceUpdate();
    },

    cancel() {
      this.close();
    },
    submitForm() {
      if (!this.form[this.column]) {
        this.$message("请填写数据");
        return;
      }

      this.$confirm("是否变更支付状态, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          RequestRemote.put(this.requestURL, this.form).then((res) => {
            this.$message({
              type: "success",
              message: res.message,
            });
            this.$emit("close", this.form, false, true);

            this.editOperationStatus();
          });
        })
        .catch((e) => {
          this.$message({
            type: "info",
            message: "已取消操作",
          });
        });
    },

    editOperationStatus() {
      this.$emit("close", this.form, false);
    },

    close() {
      this.$emit("close", this.form, false);
    },
  },
};
</script>

<style>
.algin {
  text-align: center;
}
</style>